package com.dongdongshop.serviceimpl;

import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.pojo.TbBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private TbBrandMapper tbBrandMapper;

    //查询商品管理
    @Override
    public List<TbBrand> selectBrandall() {
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        return tbBrands;
    }

    //商品管理增加
    @Override
    public Boolean insertBrand(TbBrand tbBrand) {
        try {
            Integer i = tbBrandMapper.insertSelective(tbBrand);
            if (i > 0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //删除
    @Override
    public Boolean deleteBrand(String[] ids) {
        try {
            int i = 0;
            for (int j = 0; j < ids.length; j++) {
                i = tbBrandMapper.deleteByPrimaryKey(Long.parseLong(ids[j]));
            }

            if (i > 0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //回显数据
    @Override
    public TbBrand selectById(Long id) {
        TbBrand tbBrand = tbBrandMapper.selectByPrimaryKey(id);
        return tbBrand;
    }

    //修改商品管理
    @Override
    public Boolean updateBrand(TbBrand tbBrand) {
        try {
            int i = tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
            if (i > 0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
